﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jacaranda.Model
{
    public class ContainsClause : ConditionalExpression
    {
        public Type Type1 { get; set; }

        public Type Type2 { get; set; }

        public string Property1 { get; set; }

        public string Property2 { get; set; }

        public ConditionalExpression Condition { get; set; }

        internal override string GenerateSql(Type propertyEntityType)
        {
            return string.Format("{0} IN (SELECT {1} FROM {2} WHERE {3})", 
                Metadata.Type(Type1).Fields.First(i => i.PropertyName == Property1).FieldName,
                Metadata.Type(Type2).Fields.First(i => i.PropertyName == Property2).FieldName,
                Metadata.Type(Type2).TableName,
                Condition.GenerateSql(Type2));
        }
    }
}
